package org.azj.dbOperatorComponent;
import java.sql.SQLException;

import javax.sql.DataSource;


public class ForeignKeyColumnProperty implements IForeignKeyColumnProperty{

	private IBasicTableOperation pkTable;
	private IBasicTableOperation fkTable;
	private String pkColumnName;
	private String fkColumnName;
	private String fkName;
	
	public ForeignKeyColumnProperty(
			DataSource dataSource,
			String pkTableSchem,
			String pkTableName,
			String pkColumnName,
			IBasicTableOperation fkTable,
			String fkColumnName,
			String fkName) throws SQLException
	{
		pkTable = new OperableTable(dataSource, pkTableSchem, pkTableName);
		this.fkTable = fkTable;
		
		this.pkColumnName = pkColumnName;
		this.fkColumnName = fkColumnName;
		
		this.fkName = fkName;
	}
	
	@Override
	public IBasicTableOperation getPrimaryKeyTable() {
		return pkTable;
	}

	@Override
	public IBasicTableOperation getForeignKeyTable() {
		return fkTable;
	}

	@Override
	public IColumnProperty getCorrespondingPrimaryKeyColumn() throws SQLException{
		return pkTable.getColumn(pkColumnName);
	}

	@Override
	public IColumnProperty getForeignKeyColumn() throws SQLException{
		return fkTable.getColumn(fkColumnName);
	}

	@Override
	public String getForeignKeyConstraintName()
	{
		return fkName;
	}
}
